﻿using System;
using System.Text;

namespace ProjectMadaktariMVC.Models
{
    public partial class Episode
    {
        /// <summary>
        /// Returns a comma separated list of diagnoses associated with this episode
        /// </summary>
        /// <returns></returns>
        public String GetDiagnosesList(MadaktariDataContext db)
        {
            StringBuilder sb = new StringBuilder();
            EpisodeDiagnosisRelationships.Load();
            foreach (EpisodeDiagnosisRelationship rel in EpisodeDiagnosisRelationships)
            {
                Diagnosi d = rel.Diagnosi != null ? rel.Diagnosi : ConfigurationDAO.GetDiagnosisById(db, rel.DiagnosisId);
               
                sb.Append(d.Name);
                if (EpisodeDiagnosisRelationships.IndexOf(rel) != EpisodeDiagnosisRelationships.Count - 1)
                    sb.Append(", ");
            }

            return sb.ToString();
        }
    }
}
